/* 发送Servlet，继承自HttpServlet类 */
/* 通过post请求获取id以及name参数，并插入到mysql中 */

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Example servlet showing request headers
 *
 * @author James Duncan Davidson <duncan@eng.sun.com>
 */

public class Send extends HttpServlet {

    private static final long serialVersionUID = 1L;

    @Override
    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
	    PrintWriter out = response.getWriter();
        String name = request.getParameter("name");//获取参数
        String id = request.getParameter("id");

        SqlUtil sqlUtil = new SqlUtil();//声明工具类对象
        sqlUtil.Insert(new Student(Integer.parseInt(id), name, new Long((long)-1)));//添加对象

        out.println("You put name: " + name + "  ");//返回输入，以便确保发送无误
        out.println("You put ID: " + id+ "\n");//返回输入，以便确保发送无误
    }

    @Override
    public void doPost(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException, ServletException
    {
        doGet(request, response);
    }

}
